package cn.fl.system.controller;

import cmm.comm.facade.framework.api.ISysCtrlCfgApiService;
import cmm.comm.facade.framework.condition.SysCtrlCfgQueryCondition;
import cmm.comm.facade.smscode.api.ICmmSmsCdApiService;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.multi.redis.service.IMultiRedisService;
import cmm.user.facade.system.api.ISysResPowerApiService;
import cmm.user.facade.system.api.ISysUsrModifyApiService;
import cmm.user.facade.system.condition.SysUsrQueryCondition;
import cmm.user.facade.system.constant.SysResPowerConstant;
import cmm.user.facade.system.constant.SysUsrConstant;
import cmm.user.facade.system.constant.SysUsrDeviceBindConstant;
import cmm.user.facade.system.constant.SysUsrLogoutLogConstant;
import cmm.user.facade.system.dto.SysUsrDTO;
import cmm.user.facade.system.dto.SysUsrScanDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.constant.CacheConstant;
import cn.cmm.cache.framework.service.ICacheService;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.login.loginEnum.LoginType;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysDictionaryService;
import cn.fl.system.service.ISysUsrService;
import cn.fl.system.vo.SysUsrSysRVO;
import cn.fl.system.vo.SysUsrVO;
import cn.lionbridge.center.dto.UserDTO;
import com.alibaba.fastjson.JSON;
import fl.constant.facade.framework.constant.SystemConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.SplShopAppRemindEnum;
import fl.spl.facade.spl.api.ISplCommBlackListApiService;
import fl.spl.facade.spl.condition.SplCommBlackListQC;
import fl.spl.facade.spl.constant.SplCommBlackListConstant;
import fl.spl.facade.spl.dto.SplCommBlackListDTO;
import net.sf.json.JSONArray;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.regex.Pattern;

/**
 * @Description: 系统用户表 控制层
 */
@Controller
@RequestMapping("/system/sysUsr")
public class SysUsrController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(SysUsrController.class);

	/**f
	 * SysUsr 服务层BEAN
	 */
	@Autowired
	private ISysUsrService sysUsrService;

	@Autowired
	private ISysUsrModifyApiService sysUsrModifyApiService;
	
	@Autowired
	private ISysDictionaryService sysDictionaryService;

	@Autowired
	private ISysCtrlCfgApiService sysCtrlCfgApiService ;
	
	@Autowired
	private ISplCommBlackListApiService splCommBlackListApiService;

	@Autowired
	private ICmmSmsCdApiService cmmSmsCdApiService;


	@Autowired
	private ISysResPowerApiService sysResPowerApiService;

	@Autowired
	private ICacheService cacheService;

	/**
	 * 缓存集群服务
	 */
	@Resource(name = "userRedisService")
	private IMultiRedisService userRedisService;


	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		logger.info("加载SysUsr列表页面.");
		ModelAndView view = new ModelAndView("system/sysUsr/sysSysUsrList");
		
		//状态
		List<KeyValueVO> isValidList = this.sysUsrService.searchIsValidList();
		if(isValidList!=null){
			view.addObject("isValidList", isValidList);
		}
		//性别
		List<KeyValueVO> searchSelectGenderCdList = this.sysUsrService.searchGenderCdList();
		if(searchSelectGenderCdList!=null){
			view.addObject("searchSelectGenderCdList", searchSelectGenderCdList);
		}

		
		List<KeyValueVO> usrTypCdList = this.sysUsrService.searchServiceSysCdList();
		if(usrTypCdList!=null){
			view.addObject("sysCdCdList", usrTypCdList);
		}
		return view;
	}
	
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toSplUsrListPage.do", method = { RequestMethod.GET})
	public ModelAndView toSplUsrListPage(HttpServletRequest request, HttpServletResponse response) {
		logger.info("加载SysUsr列表页面.");
		String splId = request.getParameter("splId");//如果有ID是需要指定了供应商ID,暂时来自供应商配置管理中供应商客户管理页面
		String splNm = request.getParameter("splNm");//暂时来自供应商配置管理中供应商客户管理页面
		ModelAndView view = new ModelAndView("system/sysUsr/sysSplUsrList");
		view.addObject("splId", splId);
		view.addObject("splNm", splNm);
		try {
			String yesNoCd = DictionaryConstant.CODE_SYS_YES_NO_CD;
			String isValidCd = DictionaryConstant.CODE_GRP_IS_VALID_CD;
			String genderCd = DictionaryConstant.CODE_GRP_GENDER_CD;
			String usrTypCd = DictionaryConstant.CODE_GRP_USR_TYP_CD;
			
			String sysCd = CurrentThreadContext.getFlServiceSysCd();
			String orgCd = CurrentThreadContext.getCurrentOrgCd();
			List<String> codeGrpCdList = new ArrayList<>();
			codeGrpCdList.add(yesNoCd);
			codeGrpCdList.add(isValidCd);
			codeGrpCdList.add(genderCd);
			codeGrpCdList.add(usrTypCd);
			Map<String, List<KeyValueVO>> multiKvListMap = this.sysDictionaryService.getMultiKvList(sysCd, orgCd, codeGrpCdList);
			
			String employeePosCd = fl.spl.facade.framework.constant.DictionaryConstant.SPL_EMPLOYEE_POS_CD;
			String sysCd2 = SplSystemConstant.SPL_SYS_CD;
			List<String> codeGrpCdList2 = new ArrayList<>();
			codeGrpCdList2.add(employeePosCd);
			Map<String, List<KeyValueVO>> multiKvListMap2 = this.sysDictionaryService.getMultiKvList(sysCd2, orgCd, codeGrpCdList2);
			
			//状态
			List<KeyValueVO> isValidList = multiKvListMap.get(isValidCd);
			if(isValidList!=null){
				view.addObject("isValidList", isValidList);
			}
			//性别
			List<KeyValueVO> searchSelectGenderCdList = multiKvListMap.get(genderCd);
			if(searchSelectGenderCdList!=null){
				view.addObject("searchSelectGenderCdList", searchSelectGenderCdList);
			}
			//类别
			List<KeyValueVO> usrTypCdList = multiKvListMap.get(usrTypCd);
			if(usrTypCdList!=null){
				view.addObject("usrTypCdList", usrTypCdList);
			}
			
			//是否
			List<KeyValueVO> yesNoCdList = multiKvListMap.get(yesNoCd);
			if(yesNoCdList!=null){
				view.addObject("yesNoCdList", yesNoCdList);
			}
			//员工职位
			List<KeyValueVO> employeePosCdList = multiKvListMap2.get(employeePosCd);
			if(employeePosCdList!=null){
				view.addObject("employeePosCdList", employeePosCdList);
			}
			List<KeyValueVO> sysCdList = this.sysUsrService.searchServiceSysCdList();
			if(usrTypCdList!=null){
				view.addObject("sysCdCdList", sysCdList);
			}
		} catch (Exception e) {
			BaseLogUtils.error(logger, "toSplUsrListPage", "获取数据字典错误!", CurrentThreadContext.getCurrentUserName(), e);
		}
		return view;
	}
	
	/**
	 * 选择供应商人员WIN窗口内容
	 */
	@RequestMapping(value = "/toChooseSplWinPage.do", method = { RequestMethod.GET})
	public ModelAndView toChooseSplWinPage(HttpServletRequest request, HttpServletResponse response) {
		String isMore = request.getParameter("isMore");
		ModelAndView view = new ModelAndView("system/sysUsr/chooseSplList");
		view.addObject("isMore", isMore);
		return view;
	}

	
	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		//查询条件
		
		String rlNm = request.getParameter("rlNm");
		String usrNm = request.getParameter("usrNm");
		String isValid = request.getParameter("isValid");
		String sysCd = request.getParameter("searchSysCd");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(rlNm)) {
			qc.setRlNm(rlNm);
		}
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		if (StringUtils.isNotEmpty(isValid)) {
			qc.setIsValid(Integer.parseInt(isValid));
		}
		//设置系统代码
		if(StringUtils.isNotEmpty(sysCd)){
			qc.setSysCd(sysCd);
		}else{
			qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		}
		//设置组织机构代码
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setUsrTypCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_INNER));
		page.setCondition(qc);

		logger.info("==初始化列表数据.==");
		Pager pager = this.sysUsrService.searchListPage(page);
		List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
		ListPageVO<SysUsrVO> listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		return listPage;
	}
	
	
	/**
	 * 初始化供应商用户列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initSplUsrList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initSplUsrList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		//查询条件
		
		String rlNm = request.getParameter("rlNm");
		String usrNm = request.getParameter("usrNm");
		String isValid = request.getParameter("isValid");
		String sysCd = request.getParameter("searchSysCd");
		String splNm = request.getParameter("splNm");
		String splId = request.getParameter("splId");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(rlNm)) {
			qc.setRlNm(rlNm);
		}
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		if (StringUtils.isNotEmpty(isValid)) {
			qc.setIsValid(Integer.parseInt(isValid));
		}
		if(StringUtils.isNotEmpty(splNm)){
			qc.setSplNm(splNm);
		}
		if(StringUtils.isNotEmpty(splId)){
			qc.setSplId(Long.valueOf(splId));
		}
		//设置系统代码
		if(StringUtils.isNotEmpty(sysCd)){
			qc.setSysCd(sysCd);
		}else{
			qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		}
		ListPageVO<SysUsrVO> listPage = null;
		try {
			Pager pager = null;
			//设置组织机构代码
			qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			//qc.setUsrTypCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_SPL));
			qc.setIsSplQuery(true);
			qc.setAddAppExtFlag(BaseConstant.IS_YESNO_YES);
			qc.setChannelCd(PropertiesCacheUtils.getProperty(SystemConstant.FL_SHOP_APP_CD));
			page.setCondition(qc);
			pager = this.sysUsrService.searchListPage(page);
			List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
			listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "initSplUsrList", "获取数据异常!", CurrentThreadContext.getCurrentUserName(), e);
		}
		return listPage;
	}
	
	/**
	 * 根据组织架构id以及角色id查询功能权限关联的用户列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getUsrByOrgIdRoleId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getUsrByOrgIdRoleId(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String orgId = request.getParameter("orgId");
		String roleId = request.getParameter("roleId");
		//查询条件
		
		String usrNm = request.getParameter("usrNm");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		//设置系统代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		//设置组织机构id
		if(StringUtils.isNotEmpty(orgId)){
			qc.setOrgId(Long.valueOf(orgId));
			
		}
		//设置角色id
		if(StringUtils.isNotEmpty(roleId)){
			qc.setRoleId(Long.valueOf(roleId));
			
		}

		
		page.setCondition(qc);
		
		logger.info("==根据组织架构id以及角色id查询功能权限关联的用户列表.==");
		Pager pager = this.sysUsrService.searchUsrByOrgIdRoleId(page);
		List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
		ListPageVO<SysUsrVO> listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		return listPage;
	}
	/**
	 * 剔除功能权限关联关系分页查询用户列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getUsrNotInOrgIdRoleId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getUsrNotInOrgIdRoleId(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String orgId = request.getParameter("orgId");
		String roleId = request.getParameter("roleId");
		//查询条件
		
		String usrNm = request.getParameter("usrNmSearch");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		//设置系统代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		//设置组织机构id
		if(StringUtils.isNotEmpty(orgId)){
			qc.setOrgId(Long.valueOf(orgId));
			
		}
		//设置角色id
		if(StringUtils.isNotEmpty(roleId)){
			qc.setRoleId(Long.valueOf(roleId));
		}
		qc.setUsrTypCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_INNER));
		page.setCondition(qc);
		
		
		logger.info("==剔除功能权限关联关系分页查询用户列表.==");
		Pager pager = this.sysUsrService.searchUsrNotInOrgIdRoleId(page);
		List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
		ListPageVO<SysUsrVO> listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		return listPage;
	}
	
	/**
	 * 修改数据权限查询列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getUsrByOrgIdUsrIds.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getUsrByOrgIdUsrIds(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String orgId = request.getParameter("orgId");
	
		String usrIdArrStr = request.getParameter("usrIdArr");
		String[] usrIdArr = usrIdArrStr.split(",");
		
		List<String> usrIdList = new ArrayList<String>();
		if(usrIdArr!=null && usrIdArr.length>0){
			
			Collections.addAll(usrIdList, usrIdArr);
		}
		List<Long> usrIds = new ArrayList<Long>();
		if(CollectionUtils.isNotEmpty(usrIdList)){
			
			for (String idStr : usrIdList) {
				usrIds.add(Long.valueOf(idStr));
			}
		}
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		
		//设置系统代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		//设置组织机构id
		if(StringUtils.isNotEmpty(orgId)){
			qc.setOrgId(Long.valueOf(orgId));
			
		}
		//设置用户id集合
		if(CollectionUtils.isNotEmpty(usrIds)){
			qc.setUpdUsrIds(usrIds);
		}
		
		
		page.setCondition(qc);
		
		logger.info("==修改数据权限查询用户列表.==");
		Pager pager = this.sysUsrService.searchUsrForUpdate(page);
		List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
		ListPageVO<SysUsrVO> listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		return listPage;
	}
	/**
	 * 根据组织架构id以及角色id查询数据权限关联的用户列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getUsrByOrgId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getUsrByOrgId(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String orgId = request.getParameter("orgId");
		//查询条件

		String usrNm = request.getParameter("usrNm");

		//是否为数据权限 1：是，0：否
		String isDataAuth = request.getParameter("isDataAuth") ;
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		//设置系统代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		//设置组织机构id
		if(StringUtils.isNotEmpty(orgId)){
			qc.setOrgId(Long.valueOf(orgId));
		}
		
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());

		page.setCondition(qc);
		Pager pager =null;
		logger.info("==根据组织架构id以及角色id查询数据权限关联的用户列表.==");
		if(StringUtils.isNotEmpty(orgId)){
		    if(StringUtils.isNotEmpty(isDataAuth) && BaseConstant.IS_YESNO_NO_STR.equals(isDataAuth)){
                pager = this.sysUsrService.searchFunAuthUsrByOrgId(page);
            }else{
                pager = this.sysUsrService.searchUsrByOrgId(page);
            }
		}else{
			pager=new  Pager();
		}
		
		List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
		ListPageVO<SysUsrVO> listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		return listPage;
	}
	/**
	 * 剔除数据权限关联关系分页查询用户列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getUsrNotInOrgId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getUsrNotInOrgId(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String orgId = request.getParameter("orgId");
		//查询条件
		
		String usrNm = request.getParameter("usrNmSearch");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		//设置系统代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		//设置组织机构id
		if(StringUtils.isNotEmpty(orgId)){
			qc.setOrgId(Long.valueOf(orgId));
		}
		qc.setUsrTypCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_INNER));
		page.setCondition(qc);
		
		logger.info("==剔除数据权限关联关系分页查询用户列表.==");
		Pager pager = this.sysUsrService.searchUsrNotInOrgId(page);
		List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
		ListPageVO<SysUsrVO> listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		return listPage;
	}

	/**
	 * 密码重置
	 */
	@RequestMapping(value = "/reSetPwd.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO reSetPwd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "重置成功");
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键参数不能为空！");
			return result;
		}
		List<Long> idsList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idsList.add(Long.valueOf(object.toString()));
		}
		String pwd = MD5Utils.getInstance().encrypt(PropertiesCacheUtils.getProperty(SysUsrConstant.INTT_PWD));
		try {
			boolean success = this.sysUsrService.modifyPwdSysUsr(idsList,pwd);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("重置失败！");
			}
			logger.debug("==reSetPwd==ids:" + ids);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("重置失败");
			logger.error("重置失败", ex);
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String sysCd  = request.getParameter("sysCd");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			return result;
		}
		
		if(StringUtils.isEmpty(sysCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统代码不能为空!");
			return result;
		}
		
		try {
			SysUsrVO vo = this.sysUsrService.selectById(Long.valueOf(id), sysCd);
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在！");
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("获取数据失败！");
			logger.error("获取数据失败！", ex);
		}
		return result;
	}
	
	@RequestMapping(value = "/checkIsDefPwd.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object checkIsDefPwd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_NO, "获取成功");
		try {
			UserDTO sysUsrDTO = (UserDTO)CurrentThreadContext.getValue(CurrentThreadContext.CURRENT_USER_INFO);
			if(null != sysUsrDTO){
				//密码无盐强制更新
				if(StringUtils.isEmpty(sysUsrDTO.getRefSalt())){
					result.setSuccess(BaseConstant.IS_YESNO_YES);
				}else if(null != sysUsrDTO.getRefPwdCrtTm()){
					Date refPwdCrtTm=DateUtils.getDateAddDate(sysUsrDTO.getRefPwdCrtTm(),2,3); //获取三个月后的时间
					if(refPwdCrtTm.compareTo(new Date()) <= 0){
						result.setSuccess(BaseConstant.IS_YESNO_YES);
						result.setInfo("您的密码已到期请更新！");
					}
				}
			}
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("验证失败！");
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		try {
			SysUsrVO sysUsrVO = this.getRequestParamSysUsrAdd(request);
			Long id = this.sysUsrService.add(sysUsrVO);
			result.setData(id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			logger.error("", ex);
		}
		return result;
	}
	
	/**
	 * 新增供应商用户
	 */
	@RequestMapping(value = "/addSplUsr.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addSplUsr(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		String rlSplId = request.getParameter("rlSplId");
		String employeePosCd = request.getParameter("employeePosCd");
		if(StringUtils.isEmpty(rlSplId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请选择供应商!");
			return result;
		}
		Integer isSplChg = BaseConstant.IS_YESNO_NO;
		if(null != employeePosCd && !"3".equals(employeePosCd)){
			isSplChg = BaseConstant.IS_YESNO_YES;
    	}
		try {
			SysUsrVO sysUsrVO = this.getRequestParamSysUsrAdd(request);
			
			//TODO 是否开启实际控制人ID
			SysCtrlCfgQueryCondition cfgQueryCondition = new SysCtrlCfgQueryCondition();
			cfgQueryCondition.setSysCd(SplSystemConstant.SPL_SYS_CD);
			cfgQueryCondition.setOrgCd(SplSystemConstant.DEFAULT_ORG_CD);
			cfgQueryCondition.setCtrlCode(SplSystemConstant.CTRL_CODE_CTRL_APP_LOGIN_CD);
			String buttNum = sysCtrlCfgApiService.searchSysCtrlCfgByCtrlCode(cfgQueryCondition);
			List<String> blackPhoneList = null ;
			if (StringUtils.isNotEmpty(buttNum) && (String.valueOf(BaseConstant.IS_YESNO_YES).equals(buttNum) || "2".equals(buttNum))) {
				//TODO 判断是否内部用户 jiangzg 2018-8-1 17:32:26
				SplCommBlackListQC commBlackListQC = new SplCommBlackListQC();
				commBlackListQC.setBusTypCd(SplCommBlackListConstant.SHOP_APP_LOGN_BLACK_LIST_BUS_TYP);
				commBlackListQC.setIsDel(BaseConstant.IS_YESNO_NO);
				commBlackListQC.setIsValid(BaseConstant.IS_YESNO_YES);
				List<SplCommBlackListDTO> splCommBlackListDTOs = this.splCommBlackListApiService.searchSplCommBlackListDTOs(commBlackListQC);
				if(CollectionUtils.isNotEmpty(splCommBlackListDTOs)){
					blackPhoneList = new ArrayList<>(splCommBlackListDTOs.size());
					for(SplCommBlackListDTO splCommBlackListDTO : splCommBlackListDTOs){
						if(StringUtils.isNotEmpty(splCommBlackListDTO.getPhoneFst())
								&& !blackPhoneList.contains(splCommBlackListDTO.getPhoneFst())){
							blackPhoneList.add(splCommBlackListDTO.getPhoneFst());
						}
						if(StringUtils.isNotEmpty(splCommBlackListDTO.getPhoneSec())
								&& !blackPhoneList.contains(splCommBlackListDTO.getPhoneSec())){
							blackPhoneList.add(splCommBlackListDTO.getPhoneSec());
						}
					}
					if(CollectionUtils.isNotEmpty(blackPhoneList) && blackPhoneList.contains(sysUsrVO.getUsrNm())){
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo(SplShopAppRemindEnum.getCodeNmDesc(SplShopAppRemindEnum.ADD_REMIND.getCode()));
						BaseLogUtils.info(logger, "login", SplShopAppRemindEnum.getCodeNmDesc(SplShopAppRemindEnum.ADD_REMIND.getCode()) + "狮桥用户登录名称：" + sysUsrVO.getUsrNm());
						return result;
					}
				}
            }
			sysUsrVO.setMp(sysUsrVO.getUsrNm());
			sysUsrVO.setUsrTypCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_SPL));
			
			sysUsrVO.setSplId(Long.valueOf(rlSplId));
			sysUsrVO.setIsSplChg(isSplChg);
			if(StringUtils.isNotEmpty(employeePosCd)){
				sysUsrVO.setEmployeePosCd(employeePosCd);
			}
			logger.info("==      employeePosCd      =="+sysUsrVO.getEmployeePosCd());
			Long id = this.sysUsrService.addForSplUsr(sysUsrVO);
			result.setData(id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "addSplUsr", "新增供应商用户失败!", ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "addSplUsr", "新增供应商用户失败!", ex);
		}
		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("idS");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			SysUsrVO sysUsrVO = this.getRequestParamSysUsrModify(request);
			sysUsrVO.setId(Long.valueOf(id));
			String usrNm = sysUsrVO.getUsrNm();
			Long usrId = sysUsrVO.getId();
			String sysCd = sysUsrVO.getSysCd();
			//唯一工号验证
			SysUsrQueryCondition sysUsrQueryCondition = new SysUsrQueryCondition();
			sysUsrQueryCondition.setUsrNm(usrNm);
			sysUsrQueryCondition.setSysCd(sysCd);//系统代码
			boolean pass = this.sysUsrService.checkUserInfoForModify(usrNm, usrId);
			if(!pass){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "用户已经存在,不能修改!");
			}
			
			boolean success = this.sysUsrService.modify(sysUsrVO);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("修改失败!");
			logger.error("修改失败!", ex);
		}
		return result;
	}
	
	/**
	 * 修改供应商
	 */
	@RequestMapping(value = "/modifySplUsr.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifySplUsr(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("idS");
		String employeePosCd = request.getParameter("employeePosCd");
		String rlSplId = request.getParameter("rlSplId");
		String rlSplOldId = request.getParameter("rlSplOldId");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		

		if(StringUtils.isEmpty(rlSplId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请选择供应商!");
			return result;
		}
		
		/*if(StringUtils.isEmpty(rlSplOldId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("供应商原始ID不存在!");
			return result;
		}*/
		
		Integer isSplChg = BaseConstant.IS_YESNO_NO;
		if(null != employeePosCd && !"3".equals(employeePosCd)){
			isSplChg = BaseConstant.IS_YESNO_YES;
    	}
		
		try {
			SysUsrVO sysUsrVO = this.getRequestParamSysUsrModify(request);
			sysUsrVO.setMp(sysUsrVO.getUsrNm());
			sysUsrVO.setId(Long.valueOf(id));
			String usrNm = sysUsrVO.getUsrNm();
			Long usrId = sysUsrVO.getId();
			String sysCd = sysUsrVO.getSysCd();
			//唯一工号验证
			SysUsrQueryCondition sysUsrQueryCondition = new SysUsrQueryCondition();
			sysUsrQueryCondition.setUsrNm(usrNm);
			sysUsrQueryCondition.setSysCd(sysCd);//系统代码
			boolean pass = this.sysUsrService.checkUserInfoForModify(usrNm, usrId);
			if(!pass){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "用户已经存在,不能修改!");
			}
			
			sysUsrVO.setUsrTypCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_SPL));
			sysUsrVO.setIsSplChg(isSplChg);
			if(StringUtils.isNotEmpty(employeePosCd)){
				sysUsrVO.setEmployeePosCd(employeePosCd);
			}
			sysUsrVO.setSplId(Long.valueOf(rlSplId));
			if(StringUtils.isNotEmpty(rlSplOldId)){
				sysUsrVO.setSplOldId(Long.valueOf(rlSplOldId));
			}
			boolean success = this.sysUsrService.modify(sysUsrVO);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("修改失败!");
			logger.error("修改失败!", ex);
		}
		return result;
	}
	

	/**
	 * 登录
	 */
	@RequestMapping(value = "/login.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object login(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String usrNm = request.getParameter("usrNm");
		String pwd = request.getParameter("pwd");
		String verifyCd=request.getParameter("verifyCd");

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "登录成功!");
		if (StringUtils.isBlank(usrNm)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请输入用户名称！");
			return result;
		}

		if (StringUtils.isBlank(pwd)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请输入密码！");
			return result;
		}

		try {
			//校验密码和短信验证码信息
			this.checkUsrPwdAndMsgCode(usrNm,pwd,verifyCd);
			//登录判断
			boolean pass = this.sysUsrService.login(usrNm, pwd, LoginType.PASSWORD);
			if (pass) {
				//request.getRequestDispatcher("/login/login/toIndexPage.do").forward(request, response);
				//获取开关
				Boolean resCtrl = getResPowerCtrl();
				if (resCtrl) {
					this.setRedisResPower();
				}
			} else {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("用户名或密码错误!");
			}
		}  catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("登录失败!");
			logger.error("登录失败!", ex);
		}
		return result;
	}



    /**
     * 二维码免密登录
     */
    @RequestMapping(value = "/qrcodeLogin.do", method = { RequestMethod.GET })
    @ResponseBody
    public Object qrcodeLogin(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String qrcodeId=request.getParameter("qrcodeId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "登录成功!");
		if (StringUtils.isBlank(qrcodeId)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("二维码Id不能为空！");
			return result;
		}
        try {
			String redisKey =  getQrCodeRedisKey(qrcodeId);
			SysUsrScanDTO sysUsrScanDTO = (SysUsrScanDTO) userRedisService.get(redisKey);
			if(sysUsrScanDTO == null || StringUtils.isEmpty(sysUsrScanDTO.getUserName())){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("用户名不能为空！");
				return result;
			}
			String usrNm = sysUsrScanDTO.getUserName();
            //登录判断
            boolean pass = this.sysUsrService.login(usrNm, "111111", LoginType.SCANCODE);
            if (pass) {
                //获取开关
                Boolean resCtrl = getResPowerCtrl();
                if (resCtrl) {
                    this.setRedisResPower();
                }
            } else {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("登录失败");
            }
        }  catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            logger.error(ex.getMessage(), ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("登录失败!");
            logger.error("登录失败!", ex);
        }
        return result;
    }
	
	
	/**
	 * 登录
	 */
	@RequestMapping(value = "/modifyCurrentLoginUserInfo.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyCurrentLoginUserInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String roleId = request.getParameter("roleId");
		String orgId = request.getParameter("orgId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,"切换成功!");
		if(StringUtils.isBlank(roleId) || StringUtils.isBlank(orgId) || !StringUtils.isNumeric(roleId)|| !StringUtils.isNumeric(orgId) ){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("违法数据！");
			return result;
		}
		try {
			boolean pass = this.sysUsrService.modifyCurrentLoginUserInfo(Long.valueOf(roleId), Long.valueOf(orgId));
			if(!pass){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("违法数据！");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("违法数据！");
		}
		return result;
	}
	
	
	/**
	 * 根据组织架构ID查询所有属于当前架构角色下所有的用户(属于功能的配置权限)F
	 * 如果组织架构ID不存在则查询全部用户
	 */
	@RequestMapping(value = "/searchFunAuthUsrByOrgId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object searchFunAuthUsrByOrgId(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String orgId = request.getParameter("orgId");
		//查询条件
		
		String rlNm = request.getParameter("rlNm");
		String usrNm = request.getParameter("usrNm");
		String usrTypCd = request.getParameter("usrTypCd");
		String isValid = request.getParameter("isValid");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		if (StringUtils.isNotEmpty(rlNm)) {
			qc.setRlNm(rlNm);
		}
		//过滤用户条件设置（查询有效用户和内部用户）
		if (StringUtils.isNotEmpty(usrTypCd)) {
			qc.setShowUsrTypeCd(usrTypCd);
		}
		if (StringUtils.isNotEmpty(isValid)) {
			qc.setIsValid(Integer.parseInt(isValid));
		}else {
			qc.setIsValid(1);
		}
		//设置系统代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		//设置组织机构id
//		if(StringUtils.isNotEmpty(orgId)){
//			qc.setOrgId(Long.valueOf(orgId));
//		}
		if(StringUtils.isNotEmpty(orgId)) {
			String[] arr = orgId.split(",");
			if (arr != null && arr.length > 1) {//orgid多个时批量查询，单个时单独查询
				List<Long> orgIds = new ArrayList<Long>();
				for (int i = 0; i < arr.length; i++) {
					orgIds.add(Long.valueOf(arr[i]));
				}
				qc.setOrgIdList(orgIds);
			} else {
				qc.setOrgId(Long.valueOf(orgId));
			}
		}
		page.setCondition(qc);

		logger.info("==根据组织架构id以及角色id查询数据权限关联的用户列表.==");
		Pager pager = this.sysUsrService.searchFunAuthUsrByOrgId(page);
		@SuppressWarnings("unchecked")
		List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
		ListPageVO<SysUsrVO> listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		return listPage;
	}
	
	/**
	 * 到密码修改页面
	 */
	@RequestMapping(value = "/toUsrPwdModifyPage.do", method = { RequestMethod.GET})
	public ModelAndView toUsrPwdModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String authServerPath = PropertiesCacheUtils.getProperty("web.web.properties.auth.server.path");
		request.getSession().setAttribute("authServerPath",authServerPath);
		ModelAndView view = new ModelAndView("system/sysUsr/sysUsrPwdModify");
		return view;
	}
	
	/**
	 * 修改密码
	 */
	@RequestMapping(value = "/modifyPwd.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO modifyPwd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String oldPwd = request.getParameter("oldPwd");
		String newPwd = request.getParameter("newPwd");
		String surePwd = request.getParameter("surePwd");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,"密码修改成功,请重新登录");
		if(StringUtils.isEmpty(oldPwd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("原密码不能为空！");
			return result;
		}else if(StringUtils.isEmpty(newPwd) || StringUtils.isEmpty(surePwd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新密码不能为空！");
			return result;
		}else if(oldPwd.equals(newPwd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新密码不能与原密码相同！");
			return result;
		}else if(!newPwd.equals(surePwd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("两次输入密码不一致！");
			return result;
		}else if(newPwd.length() < 8 || newPwd.length() >16) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("密码长度大于等于8小于等于16！");
			return result;
		}else if(!Pattern.matches(".*[A-Z]+.*",newPwd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("密码中必须包含大写字母！");
			return result;
		}else if(!Pattern.matches(".*[0-9]+.*",newPwd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("密码中必须包含数字！");
			return result;
		}else if(!Pattern.matches(".*[a-z]+.*",newPwd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("密码中必须包含小写字母！");
			return result;
		}else if(!Pattern.matches(".*[~!@#$%^&*()_+|<>,.?/:;'\\[\\]{}\"]+.*",newPwd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("密码中必须包含特殊字符！");
			return result;
		}

		Long id = CurrentThreadContext.getCurrentUserId();
		try {
			//原密码验证
			DataResultDTO dataResultDTO = this.sysUsrModifyApiService.modifyPwdSysUsr(null,id,oldPwd,newPwd,CurrentThreadContext.getCurrentSysCd());
			if(null == dataResultDTO){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("密码修改失败");
				BaseLogUtils.info(logger, "modifyPwd", "修改密码失败.[id:"+id+",oldPwd:"+oldPwd+",newPwd:"+newPwd+"]", CurrentThreadContext.getCurrentUserName());
			}else if(BaseConstant.IS_YESNO_NO == dataResultDTO.getSuccess()){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(dataResultDTO.getInfo());
				BaseLogUtils.info(logger, "modifyPwd", "修改密码失败."+dataResultDTO.getInfo(), CurrentThreadContext.getCurrentUserName());
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modifyPwd", "修改密码失败.[id:"+id+",oldPwd:"+oldPwd+",newPwd:"+newPwd+"]"+ ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modifyPwd", "修改密码失败.[id:"+id+",oldPwd:"+oldPwd+",newPwd:"+newPwd+"]"+ ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

    /**
     * 查询用户手机号信息
     */
    @RequestMapping(value = "/initUsrMp.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView initUsrMp(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        ModelAndView view = new ModelAndView("system/sysUsr/sysUsrMpModify");
        try {
            SysUsrDTO usrDTO = sysUsrService.getSysUsrByUsrId(CurrentThreadContext.getCurrentUserId());
            if (null != usrDTO) {
                view.addObject("usrId", usrDTO.getId());
                String mp = usrDTO.getMp();
                if (StringUtils.isBlank(mp)) {
                    mp = "未绑定手机号";
                }
                view.addObject("usrMp", mp);
            }
        } catch (BaseException ex) {
            BaseLogUtils.error(logger, "modifyPwd", "获取用户信息异常" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "modifyPwd", "获取用户信息异常" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return view;
    }

    /**
     * @MethodName modifyCurrentLoginUserInfo
     * @Description: 修改用户手机号信息
     * @Author: wangpengtao@lionbridgecapital.cn
     * @CreateDate: 2019/3/4 10:35
     * @Version: V1.0.0
     * @Param request
     * @Param response
     * @Return java.lang.Object
     * @UpdateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
     */
    @RequestMapping(value = "/modifUsrMp.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object modifUsrMp(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String newMp = request.getParameter("newMp");
		String verifyCd = request.getParameter("verifyCd");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "您手机号已更换为" + newMp);
		if (StringUtils.isBlank(newMp)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新手机号不能为空！");
			return result;
		}
		if (StringUtils.isBlank(verifyCd)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("验证码不能为空！");
			return result;
		}
		try {
			//短信发送编号
			String msgCode = SysUsrConstant.USR_CHECK_CODE+"";

			DataResultDTO resultDTO = this.cmmSmsCdApiService.getCheckCode(newMp, msgCode, verifyCd);
			if (null == resultDTO) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("手机验证码错误，请重新输入！");
				return result;
			} else if (BaseConstant.IS_YESNO_NO == resultDTO.getSuccess()) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(resultDTO.getInfo());
				return result;
			}
			//修改用户手机号处理开始
			boolean rtn = this.sysUsrService.modifySysUsrMp(newMp);
			if (rtn) {
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("您的手机号已修改为" + newMp);
			}
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "modifUsrMp", "修改用户手机号异常" + ex.getMessage(), ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("违法数据！");
		}
		return result;
	}


    /**
     * 到密码修改页面
     */
    @RequestMapping(value = "/toUsrLoginOutPage.do", method = { RequestMethod.GET})
    public ModelAndView toUsrLoginOutPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("system/sysUsr/sysUsrLoginOut");
		List<KeyValueVO> causeMap = this.sysDictionaryService.getKvList(SysUsrLogoutLogConstant.SYS_USR_LOGIN_CASH,CurrentThreadContext.getCurrentSysCd(), WebBaseConstant.SYS_P_ORG_CD);
        view.addObject("causeMap",causeMap);
        return view;
    }

	@RequestMapping(value = "/usrLoginOut.do")
	@ResponseBody
	public Object usrLogOut(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,"用户销户操作成功!");
		Long usrId=CurrentThreadContext.getCurrentUserId();
		String sysCd=CurrentThreadContext.getCurrentSysCd();
		String sysUsrCauseCd=request.getParameter("sysUsrCauseCd");
		String operDetail=request.getParameter("operDetail");

		if(StringUtils.isEmpty(usrId) || StringUtils.isEmpty(sysCd)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("用户销户失败，请重试！");
		}else if(StringUtils.isEmpty(sysUsrCauseCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请选择用户销户原因！");
		}else if("3".equals(sysUsrCauseCd) && StringUtils.isEmpty(operDetail)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请输入其他原因！");
		}else{
			//添加用户注销原因
			this.sysUsrService.addSysUsrLoginOutInfo(sysUsrCauseCd,operDetail);
			//注销用户信息
			this.sysUsrService.usrLogOutInfo(usrId,sysCd);
			//用户退出，清空缓存信息
			this.usrExit(request,response);
		}
		return result;
	}
	//********************私有方法********************//
	
	/**
	 * 获取系统用户请求公共参数(新增修改共用)
	 * @param request 请求
	 * @return 系统用户基本信息
	 */
	private SysUsrVO getRequestParamForSysUsr(HttpServletRequest request)throws BaseException{
		String usrNm = request.getParameter("usrNm");//工号（登录名）
		String rlNm = request.getParameter("rlNm");//姓名
		String mp = request.getParameter("mp");//手机号
		String email = request.getParameter("email");//邮箱
		String qq = request.getParameter("qq");//qq
		String sysCd = request.getParameter("sysCd");//系统代码
		//String openId = request.getParameter("openId");//微信
		//String regTypCd = request.getParameter("regTypCd");//注册方式
		String refIsValid = request.getParameter("refIsValid");//是否有效
		
		//验证必填项及长度
		if(StringUtils.isEmpty(usrNm) || usrNm.length() > 50){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "用户编号不能为空,并且长度不能大于20个字符。");
		}
		if(!StringUtils.isLetterAndNumber(usrNm)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请输入字母或者数字类型的工号。");
		}
		if(StringUtils.isEmpty(rlNm) || rlNm.length() > 50){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "真实名称不能为空,并且长度不能大于20个字符。");
		}
		
		
		if(StringUtils.isNotEmpty(mp) && !StringUtils.checkMobileNumber(mp)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请输入正确的手机号码!");
		}
		if(StringUtils.isNotEmpty(qq) && !StringUtils.isUnsignedNumeric(qq)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请输入正确的qq号码");
		}
		
		if(StringUtils.isEmpty(sysCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请选择所属系统!");
		}
		
		//基本信息
		SysUsrVO sysUsrVo = new SysUsrVO();
		sysUsrVo.setUsrNm(usrNm);
		sysUsrVo.setMp(mp);
		sysUsrVo.setEMail(email);
		sysUsrVo.setQq(qq);
		sysUsrVo.setSysCd(sysCd);
		//sysUsrVo.setOpenId(openId);
		//sysUsrVo.setIsDel(BaseConstant.IS_YESNO_NO);
		
		//这里要把关系数据加入
		SysUsrSysRVO sysUsrSysRVO = new SysUsrSysRVO();
		sysUsrSysRVO.setUsrNm(usrNm);
		sysUsrSysRVO.setRlNm(rlNm);
		sysUsrSysRVO.setSysCd(sysCd);
		if(StringUtils.isNotEmpty(refIsValid)){
			sysUsrSysRVO.setIsValid(Integer.valueOf(refIsValid));
		}
		sysUsrVo.setSysUsrSysRVO(sysUsrSysRVO);
		
		return sysUsrVo;
	}
	
	/**
	 * 获取系统用户请求参数(新增)
	 * @param request 请求
	 * @return 系统用户基本信息
	 */
	private SysUsrVO getRequestParamSysUsrAdd(HttpServletRequest request)throws BaseException{
		SysUsrVO sysUsrVo = this.getRequestParamForSysUsr(request);
		//String usrNm = sysUsrVo.getUsrNm();
		String sysCd = sysUsrVo.getSysCd();//系统代码
		//唯一工号验证
		/*SysUsrQueryCondition sysUsrQueryCondition = new SysUsrQueryCondition();
		sysUsrQueryCondition.setUsrNm(usrNm);
		sysUsrQueryCondition.setSysCd(sysCd);
		boolean success = this.sysUsrService.searchUsrListByUsrNm(sysUsrQueryCondition);
		if(success){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "用户已经存在!");
		}*/
		Long usrId = CurrentThreadContext.getCurrentUserId();
		sysUsrVo.setCrtTm(new Date());
		sysUsrVo.setCrtUsrId(usrId);
		sysUsrVo.setSysCd(CurrentThreadContext.getCurrentSysCd());
		sysUsrVo.setIsSysDef(BaseConstant.IS_YESNO_NO);
		sysUsrVo.setIsValid(BaseConstant.IS_YESNO_YES);
		sysUsrVo.setIsDel(BaseConstant.IS_YESNO_NO);
		String regChlCd = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_CD_FL_WEB);
		String usrTypCd = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_INNER);
		sysUsrVo.setRegChlCd(regChlCd);
		sysUsrVo.setUsrTypCd(usrTypCd);
		//TODO sysUsrVo.setPwd(MD5Utils.getInstance().encrypt(SysUsrConstant.INTT_PWD));
		
		//这里要把关系数据加入
		String defaultPwd = PropertiesCacheUtils.getProperty(SysUsrConstant.INTT_PWD);
		sysUsrVo.getSysUsrSysRVO().setPwd(MD5Utils.getInstance().encrypt(defaultPwd));
		sysUsrVo.getSysUsrSysRVO().setCrtTm(new Date());
		sysUsrVo.getSysUsrSysRVO().setCrtUsrId(usrId);
		sysUsrVo.getSysUsrSysRVO().setSysCd(sysCd);
		sysUsrVo.getSysUsrSysRVO().setRegDt(new Date());
		sysUsrVo.getSysUsrSysRVO().setIsSysDef(BaseConstant.IS_YESNO_NO);
		if(null == sysUsrVo.getSysUsrSysRVO().getIsValid()){
			sysUsrVo.getSysUsrSysRVO().setIsValid(BaseConstant.IS_YESNO_YES);
		}
		sysUsrVo.getSysUsrSysRVO().setIsDel(BaseConstant.IS_YESNO_NO);
		sysUsrVo.getSysUsrSysRVO().setRegTypCd(DictionaryConstant.SYS_USR_GRP_REG_TYP_CD_INSIDE);
		return sysUsrVo;
	}
	
	/**
	 * 获取系统用户请求参数(修改)
	 * @param request 请求
	 * @return 系统用户基本信息
	 */
	private SysUsrVO getRequestParamSysUsrModify(HttpServletRequest request)throws BaseException{
		SysUsrVO sysUsrVo = this.getRequestParamForSysUsr(request);
		sysUsrVo.setMdfTm(new Date());
		sysUsrVo.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		sysUsrVo.getSysUsrSysRVO().setMdfTm(new Date());
		sysUsrVo.getSysUsrSysRVO().setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		//sysUsrVo.getSysUsrSysRVO().setSysCd(CurrentThreadContext.getCurrentSysCd());
		return sysUsrVo;
	}
	
	/**
	 * 获取融资租赁系统用户列表
	 */
	@RequestMapping(value = "/searchUsrList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object searchUsrList(HttpServletRequest request, HttpServletResponse response) {
		//获取查询条件
		String usrNm = request.getParameter("usrNmSearch");
		String isValid = request.getParameter("isValid");
		String sysCd = request.getParameter("searchSysCd");
		//设置查询条件
		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		if (StringUtils.isNotEmpty(isValid)) {
			qc.setIsValid(Integer.parseInt(isValid));
		}
		//设置系统代码
		if(StringUtils.isNotEmpty(sysCd)){
			qc.setSysCd(sysCd);
		}else{
			qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		}
		//设置组织机构代码
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		BaseLogUtils.info(logger, "searchUsrList","==获取融资租赁系统用户列表数据.==");
		List<SysUsrDTO> list = this.sysUsrService.searchSysUsrList(qc);
		if(CollectionUtils.isNotEmpty(list)){
			BaseLogUtils.info(logger, "searchUsrList","==当前融资租赁系统用户总数为：[" + list.size() + "]==");
		}
		return list;
	}
	
	
	/**
	 * 移除供应商与用户关系
	 */
	@RequestMapping(value = "/removeSplUsrRlInfo.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeSplUsrRlInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String usrId = request.getParameter("usrId");
		String splId = request.getParameter("splId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(usrId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("用户ID不能为空！");
			return result;
		}
		if(StringUtils.isEmpty(splId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("供应商ID不能为空！");
			return result;
		}
		try {
			String usrTypCd = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_SPL);
			boolean pass = this.sysUsrService.removeSplUsrRlInfo(Long.valueOf(usrId), Long.valueOf(splId), usrTypCd);
			if(!pass){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("操作失败!");
			logger.error("操作失败!", ex);
		}

		return result;
	}
	
	/**
	 * 得到一条供应商用户记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getSplUsrById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getSplUsrById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String sysCd  = request.getParameter("sysCd");
		String splId  = request.getParameter("splId");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			return result;
		}
		
		if(StringUtils.isEmpty(sysCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统代码不能为空!");
			return result;
		}
		
		if(StringUtils.isEmpty(splId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("供应商主键不能为空!");
			return result;
		}
		
		try {
			SysUsrVO vo = this.sysUsrService.selectByIdAndSplId(Long.valueOf(id), sysCd, Long.valueOf(splId));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在！");
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("获取数据失败！");
			logger.error("获取数据失败！", ex);
		}
		return result;
	}

	/**
	 * @MethodName getAuthCd
	 * @Description: 获取短信验证码信息
	 * @Author: wangpengtao@lionbridgecapital.cn
	 * @CreateDate: 2019/3/1 15:32
	 * @Version: V1.0.0
	 * @Param request
	 * @Param response
	 * @Return java.lang.Object
	 * @UpdateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
	 */

	@RequestMapping(value = "/getAuthCd.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getAuthCd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		BaseLogUtils.info(logger, "getAuthCd", "获取短信验证码处理开始");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功");
		try {
			String newMp=request.getParameter("newMp");
			if (StringUtils.isBlank(newMp)) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("新手机号信息不能为空！");
				return result;
			}
			//短信发送编号
			String msgCode = SysUsrConstant.USR_CHECK_CODE+"";

			DataResultDTO dataResultDTO = this.sysUsrService.getAuthCdByMp(newMp, msgCode);
			if (dataResultDTO.getSuccess() != BaseConstant.IS_YESNO_YES) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("获取短信验证码失败，请重新获取！");
				return result;
			} else {
				BaseLogUtils.info(logger, "getAuthCd", "获取短信验证码成功");
				result.setInfo(dataResultDTO.getInfo());
			}
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "getAuthCd", ex.getMessage(), ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "getAuthCd", ex.getMessage(), ex);
		}
		BaseLogUtils.info(logger, "getAuthCd", "获取短信验证码处理结束");
		return result;
	}


	/**
	 * @MethodName setRedisResPower
	 * @Description: 设置本地缓存信息
	 * @Author: wangpengtao@lionbridgecapital.cn
	 * @CreateDate: 2019/5/16 14:40
	 * @Version: V1.0.0
	 * @Param
	 * @Return void
	 * @UpdateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
	 */
	private void setRedisResPower() throws BaseException {
		Object objLocalNum = cacheService.get(CurrentThreadContext.CURRENT_RES_POWER_NUM, CacheConstant.CACHE_OPERATION_LOCAL);
		BaseLogUtils.info(logger, "setRedisResPower", "objLocalNum：" + objLocalNum);

		//获取本地的标识和缓存中标识
		Integer redisNum = sysResPowerApiService.getResRedisNum(CurrentThreadContext.getCurrentSysCd());
		BaseLogUtils.info(logger, "setRedisResPower", "redisNum：" + redisNum);

		if (null == objLocalNum && null != redisNum) {
			BaseLogUtils.info(logger, "setRedisResPower", "本地缓存数据为空，刷新缓存数据开始");

			List<String> list = this.sysResPowerApiService.getAllSysResPowerUrl(CurrentThreadContext.getCurrentSysCd());
			if (CollectionUtils.isNotEmpty(list)) {
				String strUrlAlls=StringUtils.join(list,",");
				BaseLogUtils.info(logger, "setRedisResPower", "strUrlAlls:"+strUrlAlls);

				cacheService.set(CurrentThreadContext.CURRENT_RES_POWER, strUrlAlls,CacheConstant.CACHE_OPERATION_LOCAL);
			}
			//刷新所有数据，刷新本地标识
			cacheService.set(CurrentThreadContext.CURRENT_RES_POWER_NUM, redisNum,CacheConstant.CACHE_OPERATION_LOCAL);
			BaseLogUtils.info(logger, "setRedisResPower", "本地缓存数据为空，刷新缓存数据结束");

			//本地标识为空，缓存中标识不为空 || 本地标识 ！= 缓存中标识
		} else if (null != objLocalNum && null != redisNum) {
			Integer localNum = (Integer) objLocalNum;
			if (localNum < redisNum) {
				BaseLogUtils.info(logger, "setRedisResPower", "本地缓存标识低于远程缓存标识，刷新缓存开始");

				List<String> list = this.sysResPowerApiService.getAllSysResPowerUrl(CurrentThreadContext.getCurrentSysCd());
				if (CollectionUtils.isNotEmpty(list)) {
					String strUrlAlls=StringUtils.join(list,",");
					BaseLogUtils.info(logger, "setRedisResPower", "strUrlAlls:"+strUrlAlls);

					cacheService.set(CurrentThreadContext.CURRENT_RES_POWER, strUrlAlls,CacheConstant.CACHE_OPERATION_LOCAL);
				}
				//刷新所有数据，刷新本地标识
				cacheService.set(CurrentThreadContext.CURRENT_RES_POWER_NUM, redisNum,CacheConstant.CACHE_OPERATION_LOCAL);
				BaseLogUtils.info(logger, "setRedisResPower", "本地缓存标识低于远程缓存标识，刷新缓存结束");

			}
		}
	}

	/**
	 * @MethodName getResPowerCtrl
	 * @Description: 获取菜单权限开关
	 * @Author: wangpengtao@lionbridgecapital.cn
	 * @CreateDate: 2019/5/7 15:03
	 * @Version: V1.0.0
	 * @Param
	 * @Return java.lang.Boolean
	 * @UpdateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
	 */
	private Boolean getResPowerCtrl() throws BaseException {
		Boolean rtn = true;
		try {
			SysCtrlCfgQueryCondition qc = new SysCtrlCfgQueryCondition();
			qc.setSysCd(WebBaseConstant.SYS_SYS_CD);
			qc.setOrgCd(WebBaseConstant.SYS_P_ORG_CD);
			qc.setCtrlCode(SysResPowerConstant.SYS_RES_POWER_CTL);
			String code = sysCtrlCfgApiService.searchSysCtrlCfgByCtrlCode(qc);
			if (StringUtils.isNotEmpty(code) && BaseConstant.IS_YESNO_NO_STR.equals(code)) {
				rtn = false;
			}
		} catch (BaseException e) {
			BaseLogUtils.error(logger, "getResPowerCtrl", "获取开关异常，" + e.getMessage(), e);
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getResPowerCtrl", "获取开关异常，" + e.getMessage(), e);
		}
		BaseLogUtils.info(logger, "getResPowerCtrl", "获取菜单权限开关:" + rtn);
		return rtn;
	}
	/**
	 * @MethodName usrExit
	 * @Description: 用户退出
	 * @Author: wangpengtao@lionbridgecapital.cn
	 * @CreateDate: 2019/12/11 10:56
	 * @Version: V1.0.0
	 * @Param request
	 * @Param response
	 * @Return void
	 * @UpdateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
	 */
	private void usrExit(HttpServletRequest request, HttpServletResponse response){
		HttpSession session = request.getSession(true);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_USER_ID, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_USER_NAME, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_USER_INFO, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ROLE_NM, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ORG_NM, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ORG_CD, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ROLE_ID, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ORG_ID, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ORG_SHT_NM, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ORG_DISP_NM, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ROLE_GRP_ID, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ORG_TYP_CD, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ORG_RGN_CD_NM, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_ROLE_GRP_ID, null);
		CurrentThreadContext.setValue(CurrentThreadContext.CURRENT_RES_POWER_URL, null);

		session.setAttribute(CurrentThreadContext.CURRENT_USER_ID, null);
		session.setAttribute(CurrentThreadContext.CURRENT_USER_NAME, null);
		session.setAttribute(CurrentThreadContext.CURRENT_USER_INFO, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ORG_CD, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ROLE_ID, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ROLE_NM, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ORG_NM, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ORG_ID, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ORG_SHT_NM, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ORG_DISP_NM, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ROLE_GRP_ID, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ORG_TYP_CD, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ORG_RGN_CD, null);
		session.setAttribute(CurrentThreadContext.CURRENT_ORG_RGN_CD_NM, null);
		session.setAttribute(CurrentThreadContext.CURRENT_RES_POWER_URL, null);

		Subject user = SecurityUtils.getSubject();
		user.logout();
	}


	@RequestMapping(value = "/searchAuthSysUsrList.do", method = { RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object searchAuthSysUsrList(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.newWebLogger("===查询用户数据Start===request" + JSON.toJSON(request.getParameterMap())).info();
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String orgId = request.getParameter("orgId");
		String mgrType = request.getParameter("mgrType");
		String isClick = request.getParameter("isClick");
		String initTime = request.getParameter("initTime");
		String dataId = request.getParameter("dataId");
		String dataTypCd = request.getParameter("dataTypCd");
		//查询条件
		String rlNm = request.getParameter("rlNm");
		String usrNm = request.getParameter("usrNm");
		String usrTypCd = request.getParameter("usrTypCd");
		String isValid = request.getParameter("isValid");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		// 过滤用户条件设置（查询有效用户和内部用户）
		if (StringUtils.isNotEmpty(usrTypCd)) {
			qc.setUsrTypCd(usrTypCd);
		}
		if (StringUtils.isNotEmpty(isValid)) {
			qc.setIsValid(Integer.parseInt(isValid));
		}else {
			qc.setIsValid(1);
		}
		// 设置系统代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());

		if (StringUtils.isNotEmpty(isClick) && "1".equals(isClick)) {
			// 点击查询 根据姓名 工号 角色
			if (StringUtils.isNotEmpty(usrNm)) {
				qc.setUsrNm(usrNm);
			}
			if (StringUtils.isNotEmpty(rlNm)) {
				qc.setRlNm(rlNm);
			}
		}

		BaseLogUtils.newWebLogger("===查询用户数据Start===page:" + JSON.toJSONString(page) + ",qc:" + JSON.toJSONString(qc) + ",initTime:" + initTime + ",orgId:" + orgId + ",mgrType:" + mgrType + ",dataId:" + dataId).info();
		ListPageVO<SysUsrVO> sysUsrVOListPageVO = this.sysUsrService.searchAuthSysUsrList(page, qc, initTime, orgId, mgrType, dataId, dataTypCd);
		BaseLogUtils.newWebLogger("===查询用户数据End===sysUsrVOListPageVO-size:" + ((null==sysUsrVOListPageVO)?0:sysUsrVOListPageVO.getTotal())).info();
		return sysUsrVOListPageVO;
	}

	/**
	 * @MethodName checkUsrPwdAndMsgCode
	 * @Description: 校验用户名密码是否正确和短信验证码是否正确
	 * @Author: wangpengtao@lionbridgecapital.cn
	 * @CreateDate: 2019/3/20 15:57
	 * @Version: V1.0.0
	 * @Param usrNm 用户名
	 * @Param pwd 密码
	 * @Param verifyCd 短信验证码
	 * @Return void
	 * @UpdateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
	 */
	private void checkUsrPwdAndMsgCode(String usrNm, String pwd, String verifyCd) throws BaseException {
		BaseLogUtils.info(logger, "checkUsrPwd", "验证用户的用户名和密码是否正确处理开始");
		try {
			//验证码开关默认打开
			String onOff = this.sysUsrService.getCtrlUsrLogin();
			//短信发送编号
			String msgCode = SysUsrConstant.USR_CHECK_CODE+"";

			BaseLogUtils.info(logger, "login", "短信验证码开关：" + onOff);
			BaseLogUtils.info(logger, "login", "短信编号：" + msgCode);

			SysUsrDTO usrDTO = this.sysUsrService.selectSysUsrWithAuthBy(CurrentThreadContext.getCurrentSysCd(), usrNm);
			if (null == usrDTO) {
				BaseLogUtils.info(logger, "checkUsrPwdAndMsgCode", "用户名错误!");
				throw new BaseException("用户名错误!");
			}
			//校验内部非正式员工账号有效期是否到
			if(SysUsrConstant.USR_PER_TYPE_CD_2.equals(usrDTO.getRefPerTypeCd())){
				boolean rtn=this.sysUsrService.checkUsrRegDt(usrDTO);
				if(!rtn){
					throw new BaseException("对不起,您是非正式员工，您的账号使用期限已到期，如需继续使用请联系管理员！");
				}
			}

			//校验手机验证码是否正确
			if (BaseConstant.IS_YESNO_YES_STR .equals(onOff)) {
				if (StringUtils.isBlank(usrNm)) {
					BaseLogUtils.info(logger, "checkUsrPwdAndMsgCode", "请输入用户名称!");
					throw new BaseException("请输入用户名称!");
				}

				if (StringUtils.isBlank(pwd)) {
					BaseLogUtils.info(logger, "checkUsrPwdAndMsgCode", "请输入密码!");
					throw new BaseException("请输入密码!");
				}

				if (StringUtils.isBlank(verifyCd)) {
					BaseLogUtils.info(logger, "checkUsrPwdAndMsgCode", "请输入手机验证码!");
					throw new BaseException("请输入手机验证码!");
				}
				//获取用户
				if (StringUtils.isEmpty(usrDTO.getMp())) {
					BaseLogUtils.info(logger, "checkUsrPwdAndMsgCode", "手机号未维护，请联系管理员重置!");
					throw new BaseException("手机号未维护，请联系管理员重置!");
				}
				//校验短信验证码是否正确
				DataResultDTO resultDTO = this.cmmSmsCdApiService.getCheckCode(usrDTO.getMp(), msgCode, verifyCd);
				if (null == resultDTO) {
					BaseLogUtils.info(logger, "checkUsrPwdAndMsgCode", "手机验证码错误，请重新输入！");
					throw new BaseException("手机验证码错误，请重新输入！");
				} else if (BaseConstant.IS_YESNO_NO == resultDTO.getSuccess()) {
					BaseLogUtils.info(logger, "checkUsrPwdAndMsgCode", resultDTO.getInfo());
					throw new BaseException(resultDTO.getInfo());
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.error(logger, "checkUsrPwd", "验证用户的用户名和密码异常：" + e.getMessage());
			throw new BaseException(e.getMessage());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "checkUsrPwd", "验证用户的用户名和密码异常：" + e.getMessage());
			throw new BaseException(e.getMessage());
		}
		BaseLogUtils.info(logger, "checkUsrPwd", "验证用户的用户名和密码是否正确处理结束");
	}

	/**
	 * 生成二维码RedisKey
	 * @param key
	 * @return
	 */
	private String getQrCodeRedisKey(String key){
		return SysUsrDeviceBindConstant.USR_SCAN_RED + WebBaseConstant.SYS_SYS_CD + ":" + key;
	}


	/********************金诚业务系统登录用户管理*****************************/

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toJCSplUsrListPage.do", method = { RequestMethod.GET})
	public ModelAndView toJCSplUsrListPage(HttpServletRequest request, HttpServletResponse response) {
		String splId = request.getParameter("splId");//如果有ID是需要指定了供应商ID,暂时来自供应商配置管理中供应商客户管理页面
		String splNm = request.getParameter("splNm");//暂时来自供应商配置管理中供应商客户管理页面
		ModelAndView view = new ModelAndView("system/sysUsr/sysJCSplUsrList");
		view.addObject("splId", splId);
		view.addObject("splNm", splNm);
		try {

			//状态
			List<KeyValueVO> isValidList = this.sysDictionaryService.getKvList(DictionaryConstant.CODE_GRP_IS_VALID_CD,SplSystemConstant.FL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD);
			if(isValidList!=null){
				view.addObject("isValidList", isValidList);
			}
			//员工职位
			List<KeyValueVO> employeePosCdList = this.sysDictionaryService.getKvList(SplSystemConstant.SPL_EMPLOYEE_POS_CD,SplSystemConstant.JC_SPL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD);
			if(employeePosCdList!=null){
				view.addObject("employeePosCdList", employeePosCdList);
			}
			List<KeyValueVO> sysCdList1 = this.sysDictionaryService.getKvList(DictionaryConstant.CODE_SYS_DS_CD,SplSystemConstant.FL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD);
			List<KeyValueVO> sysCdList = new ArrayList<>();

			if(CollectionUtils.isNotEmpty(sysCdList1)){
				for (KeyValueVO keyValueVO : sysCdList1 ) {
					if(SplSystemConstant.JC_SPL_SYS_CD.equals(keyValueVO.getKey())){
						sysCdList.add(keyValueVO);
					}
				}
			}

			view.addObject("sysCdCdList", sysCdList);

		} catch (Exception e) {
			BaseLogUtils.error(logger, "toSplUsrListPage", "获取数据字典错误!", CurrentThreadContext.getCurrentUserName(), e);
		}
		return view;
	}

	/**
	 * 初始化金诚供应商用户列表
	 */
	@RequestMapping(value = "/initJCSplUsrList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initJCSplUsrList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		//查询条件
		String rlNm = request.getParameter("rlNm");
		String usrNm = request.getParameter("usrNm");
		String isValid = request.getParameter("isValid");
		String sysCd = request.getParameter("searchSysCd");
		String splId = request.getParameter("splId");

		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		SysUsrQueryCondition qc = new SysUsrQueryCondition();
		if (StringUtils.isNotEmpty(rlNm)) {
			qc.setRlNm(rlNm);
		}
		if (StringUtils.isNotEmpty(usrNm)) {
			qc.setUsrNm(usrNm);
		}
		if (StringUtils.isNotEmpty(isValid)) {
			qc.setIsValid(Integer.parseInt(isValid));
		}
		if(StringUtils.isNotEmpty(splId)){
			qc.setSplId(Long.valueOf(splId));
		}
		//设置系统代码
		if(StringUtils.isNotEmpty(sysCd)){
			qc.setSysCd(sysCd);
		}
		ListPageVO<SysUsrVO> listPage = null;
		try {
			page.setCondition(qc);
			Pager pager = this.sysUsrService.searchJCSplUsrListPage(page);
			List<SysUsrVO> list = (List<SysUsrVO>) pager.getResultList();
			listPage = new ListPageVO<SysUsrVO>(list, pager.getTotalCount());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "initJCSplUsrList", "获取数据异常!", CurrentThreadContext.getCurrentUserName(), e);
		}
		return listPage;
	}

	/**
	 * 得到一条JC供应商用户记录
	 *
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getJCSplUsrById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getJCSplUsrById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String usrId = request.getParameter("id");
		String sysCd  = request.getParameter("sysCd");
		String splId  = request.getParameter("splId");

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功");
		if(StringUtils.isEmpty(usrId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			return result;
		}

		if(StringUtils.isEmpty(splId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("供应商主键不能为空!");
			return result;
		}

		try {
			SysUsrVO vo = this.sysUsrService.selectJCSplUsrByIdAndSplId(Long.valueOf(usrId), splId);
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在！");
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("获取数据失败！");
			logger.error("获取数据失败！", ex);
		}
		return result;
	}

	/**
	 * 新增金诚供应商用户
	 */
	@RequestMapping(value = "/addJCSplUsr.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addJCSplUsr(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		String splId = request.getParameter("splId");
		String splNm = request.getParameter("splNm");
		String employeePosCd = request.getParameter("employeePosCd");
		if(StringUtils.isEmpty(splId) || StringUtils.isEmpty(splNm)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("splId不能为空!");
			return result;
		}
		if(StringUtils.isEmpty(employeePosCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("员工职位不能为空!");
			return result;
		}
		try {
			SysUsrVO sysUsrVO = this.getRequestParamSysUsrAdd(request);
			sysUsrVO.setMp(sysUsrVO.getUsrNm());
			sysUsrVO.getSysUsrSysRVO().setPwd(MD5Utils.getInstance().encrypt("ACd.123456"));
			if(StringUtils.isNotEmpty(sysUsrVO.getMp()) && !StringUtils.checkMobileNumber(sysUsrVO.getMp())){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请输入正确的手机号码!");
			}

			//TODO 是否开启实际控制人ID
			SysCtrlCfgQueryCondition cfgQueryCondition = new SysCtrlCfgQueryCondition();
			cfgQueryCondition.setSysCd(SplSystemConstant.SPL_SYS_CD);
			cfgQueryCondition.setOrgCd(SplSystemConstant.DEFAULT_ORG_CD);
			cfgQueryCondition.setCtrlCode(SplSystemConstant.CTRL_CODE_CTRL_APP_LOGIN_CD);
			String buttNum = sysCtrlCfgApiService.searchSysCtrlCfgByCtrlCode(cfgQueryCondition);
			List<String> blackPhoneList = null ;
			if (StringUtils.isNotEmpty(buttNum) && (String.valueOf(BaseConstant.IS_YESNO_YES).equals(buttNum) || "2".equals(buttNum))) {
				//TODO 判断是否内部用户 jiangzg 2018-8-1 17:32:26
				SplCommBlackListQC commBlackListQC = new SplCommBlackListQC();
				commBlackListQC.setBusTypCd(SplCommBlackListConstant.SHOP_APP_LOGN_BLACK_LIST_BUS_TYP);
				commBlackListQC.setIsDel(BaseConstant.IS_YESNO_NO);
				commBlackListQC.setIsValid(BaseConstant.IS_YESNO_YES);
				List<SplCommBlackListDTO> splCommBlackListDTOs = this.splCommBlackListApiService.searchSplCommBlackListDTOs(commBlackListQC);
				if(CollectionUtils.isNotEmpty(splCommBlackListDTOs)){
					blackPhoneList = new ArrayList<>(splCommBlackListDTOs.size());
					for(SplCommBlackListDTO splCommBlackListDTO : splCommBlackListDTOs){
						if(StringUtils.isNotEmpty(splCommBlackListDTO.getPhoneFst())
								&& !blackPhoneList.contains(splCommBlackListDTO.getPhoneFst())){
							blackPhoneList.add(splCommBlackListDTO.getPhoneFst());
						}
						if(StringUtils.isNotEmpty(splCommBlackListDTO.getPhoneSec())
								&& !blackPhoneList.contains(splCommBlackListDTO.getPhoneSec())){
							blackPhoneList.add(splCommBlackListDTO.getPhoneSec());
						}
					}
					if(CollectionUtils.isNotEmpty(blackPhoneList) && blackPhoneList.contains(sysUsrVO.getUsrNm())){
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo(SplShopAppRemindEnum.getCodeNmDesc(SplShopAppRemindEnum.ADD_REMIND.getCode()));
						BaseLogUtils.info(logger, "login", SplShopAppRemindEnum.getCodeNmDesc(SplShopAppRemindEnum.ADD_REMIND.getCode()) + "狮桥用户登录名称：" + sysUsrVO.getUsrNm());
						return result;
					}
				}
			}
			sysUsrVO.setUsrTypCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_SYS_USR_TYP_CD_SPL));

			sysUsrVO.setSplId(Long.valueOf(splId));
			sysUsrVO.setSplNm(splNm);
			sysUsrVO.setEmployeePosCd(employeePosCd);
			Long id = this.sysUsrService.addJCSplUsr(sysUsrVO);
			result.setData(id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "addJCSplUsr", "新增供应商用户失败!", ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "addJCSplUsr", "新增供应商用户失败!", ex);
		}
		return result;
	}

	/**
	 * 修改金诚供应商用户
	 */
	@RequestMapping(value = "/modifyJCSplUsr.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyJCSplUsr(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("idS");
		String employeePosCd = request.getParameter("employeePosCd");
		String splId = request.getParameter("splId");

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}

		if(StringUtils.isEmpty(splId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("splId不能为空!");
			return result;
		}
		if(StringUtils.isEmpty(employeePosCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("员工职位不能为空!");
			return result;
		}

		try {
			SysUsrVO sysUsrVO = this.getRequestParamSysUsrModify(request);
			sysUsrVO.setId(Long.valueOf(id));
			sysUsrVO.setEmployeePosCd(employeePosCd);
			sysUsrVO.setSplId(Long.valueOf(splId));

			boolean success = this.sysUsrService.modifyJCSplUsr(sysUsrVO);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("修改失败!");
			logger.error("修改失败!", ex);
		}
		return result;
	}


	/**
	 * 移除供应商与用户关系
	 */
	@RequestMapping(value = "/removeJCSplUsrRlInfo.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeJCSplUsrRlInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String usrId = request.getParameter("usrId");
		String splId = request.getParameter("splId");
		String employeePosCd = request.getParameter("employeePosCd");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(usrId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("用户ID不能为空！");
			return result;
		}
		if(StringUtils.isEmpty(splId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("供应商ID不能为空！");
			return result;
		}
		if(StringUtils.isEmpty(employeePosCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("员工职位不能为空！");
			return result;
		}

		try {
			List<Long> usrIds = new ArrayList<>();
			usrIds.add(Long.valueOf(usrId));
			boolean pass = this.sysUsrService.removeJCSplUsrRlInfo(usrIds, splId, employeePosCd);
			if(!pass){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("操作失败!");
			logger.error("操作失败!", ex);
		}

		return result;
	}


	/**
	 * 密码重置
	 */
	@RequestMapping(value = "/reSetJCPwd.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO reSetJCPwd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "重置成功");
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键参数不能为空！");
			return result;
		}
		List<Long> idsList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idsList.add(Long.valueOf(object.toString()));
		}
		String pwd = MD5Utils.getInstance().encrypt("ACd.123456");
		try {
			boolean success = this.sysUsrService.modifyPwdJCSysUsr(idsList,pwd);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("重置失败！");
			}
			logger.debug("==reSetPwd==ids:" + ids);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("重置失败");
			logger.error("重置失败", ex);
		}

		return result;
	}


}

